<template>
    <div>
        <HETTable ref="hetTable" :pageSize="10" :tableFields="tableFields" :tableData="tableData" :enableSearch="false"
            :total="total" @getTableData="getTableData"></HETTable>
    </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import HETTable from '~/components/common/HETTable.vue'
import {
    getGuardLogs,
    getGetGuardLogsCount
} from '~/utils/axios/defender.js'
import { useRoute } from 'vue-router'
const $route = useRoute()
const oid = $route.params.oid
const fliterObj = {
    eventTypes: [
        {
            value: 10,
            label: "进程执行",
        },
        {
            value: 11,
            label: "进程拦截",
        },
        {
            value: 20,
            label: "USB接入",
        },
        {
            value: 21,
            label: "USB拦截",
        },
        {
            value: 30,
            label: "网卡发现",
        },
        {
            value: 31,
            label: "网卡禁用",
        },
        {
            value: 40,
            label: "非法外联检测",
        },
        {
            value: 50,
            label: "BAT执行",
        },
        {
            value: 51,
            label: "BAT阻止",
        },
        {
            value: 60,
            label: "VBS执行",
        },
        {
            value: 61,
            label: "VBS阻止",
        },
        {
            value: 90,
            label: "网络接入",
        },
        {
            value: 91,
            label: "网络拦截",
        },
        {
            value: 100,
            label: "CPL执行",
        },
        {
            value: 101,
            label: "CPL阻止",
        },
        {
            value: 110,
            label: "CMD执行",
        },
        {
            value: 111,
            label: "CMD阻止",
        },
        {
            value: 120,
            label: "MSC执行",
        },
        {
            value: 121,
            label: "MSC阻止",
        },
        {
            value: 130,
            label: "MSI执行",
        },
        {
            value: 131,
            label: "MSI阻止",
        },
        {
            value: 140,
            label: "FON执行",
        },
        {
            value: 141,
            label: "FON阻止",
        },
        {
            value: 150,
            label: "WSF执行",
        },
        {
            value: 151,
            label: "WSF阻止",
        },
        {
            value: 160,
            label: "WSH执行",
        },
        {
            value: 161,
            label: "WSH阻止",
        },
        {
            value: 170,
            label: "REG执行",
        },
        {
            value: 171,
            label: "REG阻止",
        },
        {
            value: 180,
            label: "PS1执行",
        },
        {
            value: 181,
            label: "PS1阻止",
        },
        {
            value: 200,
            label: "控件注册",
        },
        {
            value: 201,
            label: "控件阻止",
        },
        {
            value: 202,
            label: "服务注册",
        },
        {
            value: 203,
            label: "服务阻止",
        },
    ],
    logTypes: [
        {
            value: "1",
            label: "应用管控日志",
        },
        {
            value: "8",
            label: "外设管控日志",
        },
        {
            value: "4",
            label: "非法外联检测日志",
        },
        {
            value: "5",
            label: "心跳日志",
        },
        {
            value: "6",
            label: "扫描日志",
        },
    ]
}
const tableFields = [
    { name: "datetime", label: "时间", width: '170px' },
    { name: "logtype", label: "日志类型", width: '160px' },
    { name: "operation_name", label: "操作名" },
    { name: "event_type", label: "事件类型" },
    { name: "priority", label: "优先级", width: '160px' }
];
const tableData = ref()
const hetTable = ref()
const total = ref(0)
let logtypeFilter = '';
let event_typeFilter = '';
const filterEnumeration = (arr,val) => {
    return arr.filter(item => {
        return item.value == val
    })
}
async function getTableData(countParams, searchParams) {
    delete searchParams.$orderby;
    searchParams.oid = oid;
    let tableDataReq = await getGuardLogs(searchParams)
    let tableCount = await getGetGuardLogsCount({ oid: oid })
    tableData.value = tableDataReq.data.map(item => {
    let logtypeFilter = filterEnumeration(fliterObj.logTypes,item.logtype)[0].label;
    let event_typeFilter = filterEnumeration(fliterObj.eventTypes,item.event_type)[0].label;
        return {
            ...item,
            logtype:logtypeFilter,
            event_type:event_typeFilter,
        }
    })
    total.value = tableCount.data
    hetTable.value.finish();
}
</script>

<style lang="scss" scoped></style>